<?php
/* SVN FILE: $Id: routes.php 7945 2008-12-19 02:16:01Z gwoo $ */
/**
 * Short description for file.
 *
 * In this file, you set up routes to your controllers and their actions.
 * Routes are very important mechanism that allows you to freely connect
 * different urls to chosen controllers and their actions (functions).
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app.config
 * @since         CakePHP(tm) v 0.2.9
 * @version       $Revision: 7945 $
 * @modifiedby    $LastChangedBy: gwoo $
 * @lastmodified  $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * Here, we are connecting '/' (base path) to controller called 'Pages',
 * its action called 'display', and we pass a param to select the view file
 * to use (in this case, /app/views/pages/home.ctp)...
 */

	// Edited July 20th, 2009
	// Triaging routes based on whether or not they have a valid subdomain
	$subdomain = substr($_SERVER["HTTP_HOST"], 0, strpos($_SERVER["HTTP_HOST"], "."));
	// define values that should NOT be affected by this test:
	$donot = array(
				'potholepatrol',
				'holisticnetworking',
				'cake');
	if (!in_array($subdomain, $donot)) {
	// We have a metro specified in the subdomain (subdomains handled by Apache)
	// Route all traffic that should go to metro-based URLS
		// Administrative functions for towns
		Router::connect('/towns/add', array('controller' => 'towns', 'action' => 'add'));
		Router::connect('/towns/modify/*', array('controller' => 'towns', 'action' => 'modify'));
		Router::connect('/towns/delete/*', array('controller' => 'towns', 'action' => 'delete'));
		// Custom routing element: view, add, modify or delete a pothole:
		Router::connect(
			'/:town-name/:action/:id',
			array('controller' => 'potholes'),
			array(
				'town-name' => '^[a-z][a-z/-]*[a-z]$',
				'id' => '^[a-z0-9][a-z0-9/-]*[a-z0-9]$'));
		// Custom routing element: view town:
		Router::connect(
			'/:town-name',
			array('controller' => 'towns',
				'action' => 'view'),
			array('town-name' => '^[a-z][a-z/-]*[a-z]$'));
		// Finally, if none of the above conditions are met, load the Metro home page:
		Router::connect('/', array('controller' => 'metros', 'action' => 'view', $subdomain));
	} else {
	// There is no subdomain being used.
		// Users
		Router::connect('/users/add', array('controller' => 'users', 'action' => 'add'));
		Router::connect('/users/view/*', array('controller' => 'users', 'action' => 'view'));
		Router::connect('/users/edit/*', array('controller' => 'users', 'action' => 'edit'));
		Router::connect('/users/delete/*', array('controller' => 'users', 'action' => 'delete'));
		Router::connect('/users/register/*', array('controller' => 'users', 'action' => 'register'));
		Router::connect('/users', array('controller' => 'users', 'action' => 'index'));
		// Pages
		Router::connect('/pages/add', array('controller' => 'pages', 'action' => 'add'));
		Router::connect('/pages/edit/*', array('controller' => 'pages', 'action' => 'edit'));
		Router::connect('/pages/delete/*', array('controller' => 'pages', 'action' => 'delete'));
		Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'view'));
		Router::connect('/pages', array('controller' => 'pages', 'action' => 'index'));
		// Metros: Admin only!
		Router::connect('/metros/add', array('controller' => 'metros', 'action' => 'add'));
		Router::connect('/metros/modify/*', array('controller' => 'metros', 'action' => 'modify'));
		Router::connect('/metros/delete/*', array('controller' => 'metros', 'action' => 'delete'));
		Router::connect('/metros/*', array('controller' => 'metros', 'action' => 'viewAdmin'));
		Router::connect('/metros', array('controller' => 'metros', 'action' => 'indexAdmin'));
		/* Errors: anything that doesn't conform to the above.*/
		Router::connect('/:error/*', 
			array('controller' => 'pages', 'action' => 'error'),
			array('error' => '[^"\r\n]+'));
		// Finally, if nothing else is added to the domain name, let's go home:
		Router::connect('/', array('controller' => 'pages', 'action' => 'home'));
	}

?>